package com.resou.reader.paycenter.p;

import android.arch.lifecycle.LifecycleOwner;
import android.support.annotation.NonNull;

import com.resou.reader.api.ApiImp;
import com.resou.reader.api.entry.CouponBean;
import com.resou.reader.api.entry.Result;
import com.resou.reader.api.entry.ResultList;
import com.resou.reader.api.entry.VIPConfigBean;
import com.resou.reader.api.service.HotTicketService;
import com.resou.reader.api.service.PayService;
import com.resou.reader.api.service.StoreService;
import com.resou.reader.base.m.IModel;
import com.resou.reader.base.p.BasePresenter;
import com.resou.reader.paycenter.v.IVIPCenterView;
import com.resou.reader.paycenter.v.IWalletView;
import com.resou.reader.utils.UserUtil;

import java.util.List;

import io.reactivex.Observer;
import io.reactivex.Scheduler;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.disposables.Disposable;
import io.reactivex.schedulers.Schedulers;

public class WalletPresenter extends BasePresenter<IWalletView, IModel> {

    HotTicketService storeService;

    public WalletPresenter(IWalletView walletView) {
        this.view = walletView;
        storeService = ApiImp.getInstance().getService(HotTicketService.class);
    }



    /**
     * 查询可用优惠券数量
     */
    public void quearCouponNum() {
        storeService.quearHotTicket(UserUtil.getToken(), 0, 0, 10000)
                .subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Observer<ResultList<CouponBean>>() {
                    @Override
                    public void onSubscribe(Disposable d) {
                    }
                    @Override
                    public void onNext(ResultList<CouponBean> couponBeanResultList) {
                        if (couponBeanResultList.getData() == null || couponBeanResultList.getData().size() == 0) {
                            view.showCouponNum(0);
                        } else {
                            view.showCouponNum(couponBeanResultList.getData().size());
                        }
                    }

                    @Override
                    public void onError(Throwable e) {
                        view.showCouponNum(0);
                    }

                    @Override
                    public void onComplete() {

                    }
                });
    }
}
